const pageTitle = (name) => {
    return `pagesTitle.${name}`
}
/*
 * 后台基础静态路由
 */
const adminBaseRoute = {
    path: '/admin',
    name: 'admin',
    component: () => import('/layouts/index.vue'),
    redirect: '/admin/loading',
    meta: {
        title: pageTitle('admin'),
    },
    children: [
        {
            path: 'loading/:to?',
            name: 'adminMainLoading',
            component: () => import('/layouts/common/components/loading.vue'),
            meta: {
                title: pageTitle('Loading'),
            },
        },
    ],
}

/*
 * 静态路由
 */
const staticRoutes = [
    {
        path: '/',
        name: 'admin',
        component: () => import('/layouts/index.vue'),
        redirect: '/index',
        meta: {
            title: pageTitle('admin'),
        },
        children: [
            {
                // 首页
                path: '/index',
                name: 'index',
                component: () => import('/views/dashboard/index.vue'),
                meta: {
                    title: '控制台',
                    addtab: true
                },
            },
            {
                // 首页
                path: 'admin/index',
                name: 'admin/index',
                component: () => import('/views/dashboard/index.vue'),
                meta: {
                    title: '控制台',
                    addtab: true
                },
            },
            {
                path: 'loading/:to?',
                name: 'adminMainLoading',
                component: () => import('/layouts/common/components/loading.vue'),
                meta: {
                    title: pageTitle('Loading'),
                },
            },
            {
                path: '/admin/auth/admin',
                name: 'authAdmin',
                component: () => import('/views/dashboard/demo.vue'),
                meta: {
                    title: '管理员管理',
                    addtab: true
                },
            },
            {
                path: '/admin/account/list',
                name: 'accountList',
                component: () => import('/views/account/account.vue'),
                meta: {
                    title: '账号列表',
                    addtab: true
                },
            },
            {
                path: '/admin/account/detail',
                name: 'accountDetail',
                component: () => import('/views/account/detail.vue'),
                meta: {
                    title: '账号明细',
                    addtab: true
                },
            },
            {
                path: '/admin/bank/list',
                name: 'bankList',
                component: () => import('/views/bank/list.vue'),
                meta: {
                    title: '银行列表',
                    addtab: true
                },
            },
            {
                path: '/admin/bank/config',
                name: 'bankConfig',
                component: () => import('/views/bank/config.vue'),
                meta: {
                    title: '限流配置',
                    addtab: true
                },
            }
        ],
    },
    {
        // 登录页
        path: '/login',
        name: 'login',
        component: () => import('/views/login/index.vue'),
        meta: {
            title: pageTitle('login'),
        },
    },
    {
        // 管理员登录页
        path: '/admin/login',
        name: 'adminLogin',
        component: () => import('@/views/backend/login.vue'),
        meta: {
            title: pageTitle('adminLogin'),
        },
    },
    {
        // 会员登录页
        path: '/user/login',
        name: 'userLogin',
        component: () => import('@/views/frontend/user/login.vue'),
        meta: {
            title: pageTitle('userLogin'),
        },
    },
    {
        path: '/:path(.*)*',
        redirect: '/404',
    },
    {
        // 404
        path: '/404',
        name: 'notFound',
        component: () => import('/views/404.vue'),
        meta: {
            title: pageTitle('notFound'), // 页面不存在
        },
    },
    {
        // 后台找不到页面了-可能是路由未加载上
        path: '/admin:path(.*)*',
        redirect: (to) => {
            return {
                name: 'adminMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 无权限访问
        path: '/401',
        name: 'noPower',
        component: () => import('@/views/common/error/401.vue'),
        meta: {
            title: pageTitle('noPower'),
        },
    },
    {
        path: '/admin/Test',
        name: 'Test',
        component: () => import('/views/account.vue'),
        meta: {
            title: '测试',
            addtab: true
        },
    },
]

export {staticRoutes, adminBaseRoute}
